﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    public class LoaiDatBLL
    {

        LandEntities data = new LandEntities();
        public LoaiDatBLL()
        { }

        public List<LOAIDAT> DanhSachLoaiDat()
        {
            var loaidat= from ld in data.LOAIDATs
                         select ld;
            return loaidat.ToList<LOAIDAT>();
        }

        public void ThemLoaiDat(string maLd, string tenLd, string mieuta)
        {
            LOAIDAT loaidat = new LOAIDAT();
            loaidat.MALOAIDAT= maLd;
            loaidat.TENLOAIDAT= tenLd;
            loaidat.MIEUTA = mieuta;
            data.LOAIDATs.AddObject(loaidat);
            data.SaveChanges();
        }

        public void SuaLoaiDat(string maLd, string tenLd, string mieuta)
        {
            LOAIDAT loaidat = data.LOAIDATs.Single(ld=>ld.MALOAIDAT==maLd);
            loaidat.TENLOAIDAT=tenLd;
            loaidat.MIEUTA= mieuta;
            data.SaveChanges();
        }

        public void XoaLoaiDat(string maLd)
        {
            LOAIDAT loaidat = data.LOAIDATs.Single(ld=>ld.MALOAIDAT==maLd);
            data.LOAIDATs.DeleteObject(loaidat);
        }

    }
}
